<template>
  <div class="artical-detail">
    <NavBar title="详情" />
    <p class="title">{{ detail.title }}</p>
    <p class="time">{{ detail.dateandtime }}</p>
    <p class="content" v-html="detail.content"></p>
  </div>
</template>

<script>
import { ref } from "vue";
import { getArticleDetailt } from "@/api/index";
import { useRoute } from "vue-router";
import NavBar from "@/components/NavBar.vue";

export default {
  components: {
    NavBar,
  },
  setup() {
    const detail = ref({});
    const route = useRoute();
    const showHtml = (str) => {
      return str
        // .replace(str ? /&(?!#?\w+;)/g : /&/g, "&amp;")
        .replace(/&amp;/g, "&")
        .replace(/&lt;/g, "<")
        .replace(/&gt;/g, ">")
        .replace(/&quot;/g, '"')
        .replace(/&#39;/g, "'")
        .replace(/&ldquo;/g, '“')
        .replace(/&rdquo;/g, '”');
    };
    const getData = async () => {
      let params = {
        Fid: route.query.fid,
      };
      getArticleDetailt(params).then((res) => {
        detail.value = res.data;
        detail.value.content = showHtml(res.data.content);
      });
    };

    getData();

    return {
      detail,
      getData,
    };
  },
};
</script>

<style lang="scss" scoped>
.artical-detail {
  .title {
    padding: 0 10px;
    font-size: 16px;
    font-weight: bold;
    text-align: center;
  }
  .time {
    margin-bottom: 20px;
    font-size: 12px;
    text-align: center;
  }
  .content {
    padding: 0 16px;
  }
}
</style>
<style lang="scss">
.artical-detail {
  img {
    max-width: 100%;
  }
}
</style>